package com.prs.crm.action.sys;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;

import com.prs.crm.domain.sys.InfoDefaultTitle;
import com.prs.crm.service.sys.InfoDefaultTitleService;

public class InfoDefaultTitleAction extends BaseAction{

	private static final long serialVersionUID = 1L;
	private InfoDefaultTitle infoDefaultTitle;
	private InfoDefaultTitleService infoDefaultTitleService;
	private String serCode;
	public String getSerCode() {
		return serCode;
	}
	public void setSerCode(String serCode) {
		this.serCode = serCode;
	}
	public InfoDefaultTitle getInfoDefaultTitle() {
		return infoDefaultTitle;
	}
	public void setInfoDefaultTitle(InfoDefaultTitle infoDefaultTitle) {
		this.infoDefaultTitle = infoDefaultTitle;
	}
	public InfoDefaultTitleService getInfoDefaultTitleService() {
		return infoDefaultTitleService;
	}
	public void setInfoDefaultTitleService(
			InfoDefaultTitleService infoDefaultTitleService) {
		this.infoDefaultTitleService = infoDefaultTitleService;
	}
	
	@Action("editInfoDefaultTitle")
	public String editInfoDefaultTitle(){
		this.infoDefaultTitle=this.getInfoDefaultTitleService().getInfoDefaultTitle(serCode);
		return SUCCESS;
	}
	@Action(value="saveInfoDefaultTitle",results={
			@Result(name="success",type="redirect",location="editInfoDefaultTitle?serCode=${infoDefaultTitle.getType()}"),
			@Result(name="error",type="chain",location="editInfoDefaultTitle?serCode=${infoDefaultTitle.getType()}")
	})
	public String saveInfoDefaultTitle(){
		InfoDefaultTitle info =this.infoDefaultTitleService.getInfoDefaultTitle("it01");
		if(info==null){
			info=new InfoDefaultTitle();
			info.setType("it01");
			info.setCssEdit(infoDefaultTitle.getCssEdit());
			info.setCssShow(infoDefaultTitle.getCssShow());
			this.getInfoDefaultTitleService().save(info);
		}else{
			this.getInfoDefaultTitleService().submit(info);
		}
		infoDefaultTitle=info;
		return SUCCESS;
	}
	@Action(value="saveInfoDefault",results={
			@Result(name="success",type="redirect",location="editInfoDefaultTitle?serCode=${infoDefaultTitle.getType()}"),
			@Result(name="error",type="chain",location="editInfoDefaultTitle?serCode=${infoDefaultTitle.getType()}")
	})
	public String saveInfoDefault(){
		InfoDefaultTitle info =this.infoDefaultTitleService.getInfoDefaultTitle("it01");
		if(info==null){
			info=new InfoDefaultTitle();
			info.setType("it01");
			info.setCssEdit(infoDefaultTitle.getCssEdit());
			info.setCssShow(infoDefaultTitle.getCssShow());
			this.getInfoDefaultTitleService().save(info);
		}else{
			info.setCssEdit("");
			info.setCssShow("");
			this.getInfoDefaultTitleService().submit(info);
		}
		infoDefaultTitle=info;
		return SUCCESS;
	}
}
